"""
使用requests请求代理服务器
请求http和https网页均适用
"""

import requests

def get_proxies():
    # 提取代理API接口，获取1个代理IP
    api_url = "https://dps.kdlapi.com/api/getdps/?secret_id=oot1se87ohu1kv46n9ft&signature=ig8mqtakimt2ausjz2hqsu47dnm9k9u6&num=1&sep=1"  # API接口


    # 获取API接口返回的代理IP  ip:port
    proxy_ip = requests.get(api_url).text

    # 用户名密码认证(私密代理/独享代理)
    username = "d2898838389"
    password = "yag7i6dp"
    proxies = {
        "http": "http://%(user)s:%(pwd)s@%(proxy)s/" % {"user": username, "pwd": password, "proxy": proxy_ip},
        "https": "http://%(user)s:%(pwd)s@%(proxy)s/" % {"user": username, "pwd": password, "proxy": proxy_ip}
    }
    print(f'获取代理 {proxies}')

    # 白名单方式（需提前设置白名单）
    # proxies = {
    #     "http": "http://%(proxy)s/" % {"proxy": proxy_ip},
    #     "https": "http://%(proxy)s/" % {"proxy": proxy_ip}
    # }

    return proxies

# key = "age"
# value = 10
# print(f"{key} {value}")
# print("%s %s" % (key, value))
#
# print("%(k)s %(v)s" % {"k": key, "v": value})

if __name__ == '__main__':
    get_proxies()


def get_proxy_poll(num):
    return None